home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / SourceCode / Registration / RegSupport.m < prev    next >
Encoding:
Text File  |  1992-12-19  |  3.1 KB  |  145 lines

  1. /*
  2.  * (C) 1992 Simson Garfinkel and Associates, Inc.
  3.  *
  4.  * NeXTSTEP developers may freely use and redistribute this software as long
  5.  * as credit is given to Simson Garfinkel and Associates.
  6.  *
  7.  * EXPORT RESTRICTIONS:
  8.  *
  9.  * You may not ship the source-code module des.c outside of the US or canada.
  10.  *
  11.  * You may ship a program which uses the des.o compiled module outside of the
  12.  * United States to any type T or type V country as long as you do not provide
  13.  * cryptographic services to the user in your program and you clearly
  14.  * declare "commodity control number 5D11A" on your export declaration.
  15.  *
  16.  * Type T countries include all countries in the Western Hemisphere except Cuba.
  17.  * Type V countries include all countries in the Eastern Hemisphere except
  18.  * the previous communist block countries and the People's Republic of China,
  19.  * Vietnam, Cambodia, and Laos.
  20.  *
  21.  * For further information, contact the Office of Export Control:
  22.  *
  23.  *    Bureau of Export Administration
  24.  *    P.O. Box 273
  25.  *    Washington, DC 20044
  26.  *    202-377-2694
  27.  */
  28.  
  29. /* RegSupport.m:
  30.  *
  31.  * Support functions for registration.  Usually included by
  32.  * Registration.m
  33.  */
  34.  
  35. /****************************************************************
  36.   UTILITY FUNCTIONS
  37.  ****************************************************************/
  38.  
  39. char    *binary_to_hex(void *binary,int len,char *buf)
  40. {
  41.     char    buf2[8];
  42.     int    i;
  43.     unsigned char *cc = binary;
  44.  
  45.     buf[0]    = 0;
  46.     for(i=0;i<len;i++){
  47.         sprintf(buf2,"%02X",cc[i]);
  48.         strcat(buf,buf2);
  49.         if((i & 0x01) == 0x01 && (i!=len-1)){
  50.             strcat(buf,"-");
  51.         }
  52.     }
  53.     return buf;
  54. }
  55.  
  56. void    *hex_to_binary(const char *buf,void *binary,int len)
  57. {
  58.     const char     *cc = buf;
  59.     unsigned char     *out = binary;
  60.  
  61.     int    i;
  62.  
  63.     for(i=0;i<len;i++){
  64.         char    digit;
  65.         int    i;
  66.         
  67.         if(*cc == '-') cc++;
  68.         *out    = 0;
  69.         for(i=0;i<2;i++){
  70.             digit         = NXToUpper(*cc++);
  71.             if(digit=='L') digit='1';
  72.             if(digit=='O') digit='0';
  73.             *out    = (*out << 4);
  74.             if(NXIsDigit(digit)) *out += digit - '0';
  75.             if(NXIsAlpha(digit)) *out += digit - 'A' + 10;
  76.         }
  77.         out++;
  78.     }
  79.  
  80.     return binary;
  81. }
  82.  
  83. int    checksum(void *data,int len)
  84. {
  85.     unsigned char *cc = data;
  86.     int     i;
  87.     unsigned char sum;
  88.  
  89.     sum    = 0;
  90.     for(i=0;i<len;i++){
  91.         sum    += cc[i];
  92.     }
  93.     return sum;
  94. }
  95.  
  96. int    checksum2(void *data,int len)
  97. {
  98.     unsigned short *dd = data;
  99.     int     i;
  100.     unsigned short dsum;
  101.  
  102.     dsum    = 0;
  103.     for(i=0;i<len/2;i++){
  104.         dsum    += dd[i];
  105.     }
  106.     return dsum;
  107. }
  108.  
  109. void    asciiToKey(char *ascii,char *key)
  110. {
  111.     memset(key,0,8);
  112.     strncpy(key,ascii,8);
  113. }
  114.  
  115. char     *hostNumberToAscii(int address,char *buf)
  116. {
  117.     sprintf(buf,"%u.%u.%u.%u",
  118.         (address >> 24) & 0xff,
  119.         (address >> 16) & 0xff,
  120.         (address >> 8)  & 0xff,
  121.         (address >> 0)  & 0xff);
  122.     return buf;
  123. }
  124.  
  125. char    *hostName(int  address,char *buf)
  126. {
  127.    struct  hostent     *hp;
  128.    
  129.    hp = gethostbyaddr((char *)&address,4,AF_INET);
  130.    
  131.    return hp ? hp->h_name : hostNumberToAscii(address,buf);
  132. }
  133.  
  134. /****************************************************************
  135.  MESSAGES FOR DEALING WITH LICENSE STRINGS AND SUCH
  136.  ****************************************************************/
  137.  
  138. int    lsNumUsers(struct licenseString *ls)
  139. {
  140.     return (ls->maxMachines[0] << 8) + ls->maxMachines[1];
  141.  
  142. }
  143.  
  144.  
  145.